package ejemplo;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;

public class ShellAdrian extends Shell {
	static Composite composite[]=new Composite[2];

	/**
	 * Launch the application.
	 * 
	 * @param args
	 */
	public static void main(String args[]) {
		try {
			Display display = Display.getDefault();
			ShellAdrian shell = new ShellAdrian(display);
			shell.open();
			shell.layout();
			while (!shell.isDisposed()) {
				if (!display.readAndDispatch()) {
					display.sleep();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the shell.
	 * 
	 * @param display
	 */
	public ShellAdrian(Display display) {
		super(display, SWT.SHELL_TRIM);
		setLayout(new FormLayout());

		Menu menu = new Menu(this, SWT.BAR);
		setMenuBar(menu);

		MenuItem menuArchivo = new MenuItem(menu, SWT.CASCADE);
		menuArchivo.setText("Archivo");

		Menu submenuArchivo = new Menu(this, SWT.DROP_DOWN);
		menuArchivo.setMenu(submenuArchivo);

		MenuItem ItemInsidencias = new MenuItem(submenuArchivo, SWT.PUSH);
		ItemInsidencias.setText("Incidencias");
		MenuItem ItemTipoClientes = new MenuItem(submenuArchivo, SWT.PUSH);
		ItemTipoClientes.setText("TipoClientes");
		MenuItem ItemSalir = new MenuItem(submenuArchivo, SWT.PUSH);
		ItemSalir.setText("Salir");

		MenuItem mntmEdicin = new MenuItem(menu, SWT.NONE);
		mntmEdicin.setText("Edici\u00F3n");

		ItemInsidencias.addSelectionListener(new MostrarInsidencias());
		ItemTipoClientes.addSelectionListener(new MostrarTipoClientes());
		ItemSalir.addSelectionListener(new Exit());

		composite[0] = new Insidencias(this, SWT.NONE);
		composite[1] = new TipoClientes(this, SWT.NONE);
		FormData fd_composite = new FormData();
		fd_composite.top = new FormAttachment(0, 22);
		fd_composite.left = new FormAttachment(0);
		fd_composite.bottom = new FormAttachment(0, 342);
		fd_composite.right = new FormAttachment(0, 434);
		composite[0].setLayoutData(fd_composite);
		composite[1].setLayoutData(fd_composite);
		composite[0].setVisible(false);
		composite[1].setVisible(false);
		createContents();
	}

	class MostrarInsidencias implements SelectionListener {
		public void widgetSelected(SelectionEvent event) {
			if(composite[1].isVisible())
				composite[1].setVisible(false);
			composite[0].setVisible(true);
		}

		public void widgetDefaultSelected(SelectionEvent event) {
		}
	}
	class MostrarTipoClientes implements SelectionListener {
		public void widgetSelected(SelectionEvent event) {
			if(composite[0].isVisible())
				composite[0].setVisible(false);
			composite[1].setVisible(true);
		}

		public void widgetDefaultSelected(SelectionEvent event) {
		}
	}
	class Exit implements SelectionListener {
		public void widgetSelected(SelectionEvent event) {
			System.exit(0);
		}

		public void widgetDefaultSelected(SelectionEvent event) {
		}
	}

	/**
	 * Create contents of the shell.
	 */
	protected void createContents() {
		setText("SWT Application");
		setSize(450, 400);

	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
}
